package org.deltaset.meta.internal;

import java.util.List;
import java.util.Map;
import org.deltaset.meta.MetaAction;
import org.deltaset.meta.MetaField;
import org.deltaset.meta.annotation.DsViewType;

/**
 *
 * @author dmakariev
 */
class MetaClassImpl {

    private final Class entityClass;
    private final Map<DsViewType, List<MetaField>> orderedFieldsMap;
    private final List<MetaField> allMetaFields;
    /////
    private final MetaAction findByIdAction;
    private final MetaAction defaultAction;
    private final Map<MetaActionGroupType, List<MetaAction>> actionMap;
    private final List<MetaAction> allMetaActions;
    
    private final MetaField idField = null;
    
    private final boolean isCollection = false;
    private final boolean isVoid = false;
    private final boolean isPrimitive;
    private final boolean isEmpty = false;

    MetaClassImpl(Class entityClass,
            Map<DsViewType, List<MetaField>> orderedFieldsMap,
            List<MetaField> allMetaFields,
            MetaAction findByIdAction,
            MetaAction defaultAction,
            Map<MetaActionGroupType, List<MetaAction>> actionMap,
            List<MetaAction> allMetaActions,
            boolean isPrimitive) {
        this.entityClass = entityClass;
        this.orderedFieldsMap = orderedFieldsMap;
        this.allMetaFields = allMetaFields;
        this.findByIdAction = findByIdAction;
        this.defaultAction = defaultAction;

        this.actionMap = actionMap;
        this.allMetaActions = allMetaActions;
        
        this.isPrimitive = isPrimitive;
    }

    MetaAction getFindByIdAction() {
        return findByIdAction;
    }

    MetaAction getDefaultAction() {
        return defaultAction;
    }

    List<MetaAction> getActionsFor(MetaActionGroupType groupType) {
        return actionMap.get(groupType);
    }

    List<MetaAction> getActions() {
        return allMetaActions;
    }

    List<MetaField> getFields() {
        return allMetaFields;
    }

    Class getEntityClass() {
        return entityClass;
    }

    //TODO: find why there is javax.el.BeanELResolver can not access a member ... exception when Collections.unmodifiableList is used
    List<MetaField> getFieldsFor(final DsViewType type) {
        return orderedFieldsMap.get(type);
    }

    MetaField getIdField() {
        return idField;
    }        
    
    boolean isCollection() {
        return isCollection;
    }

    boolean isVoid() {
        return isVoid;
    }
    
    boolean isPrimitive() {
        return isPrimitive;
    }
    
    boolean isEmpty() {
        //return fields.isEmpty() && actions.isEmpty();
        return isEmpty;
    }
}
